#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
const int M = 1e6 + 5;
const int INF = 0x3f3f3f3f;
ll p[N], T, n, m, L, V;
struct Car
{
    ll d, v, a, beg = INF, end = INF - 1;
} c[N];
vector<int> vis[M];
bool cc[N];
void calc(ll x)
{
    if (c[x].a == 0)
    {
        if (c[x].v > V)
        {
            c[x].beg = c[x].d, c[x].end = L;
        }
    }
    else if (c[x].a > 0)
    {
        if (c[x].v > V)
            c[x].beg = c[x].d, c[x].end = L;
        else if (c[x].v == V)
            c[x].beg = min(L, c[x].d + 1), c[x].end = L;
        else
        {
            double tmp = (V * V - c[x].v * c[x].v) * 0.5 / c[x].a;
            if (ceil(tmp) == tmp)
                c[x].beg = c[x].d + tmp + 1;
            else
                c[x].beg = c[x].d + ceil(tmp);
            c[x].end = L;
        }
    }
    else
    {
        if (c[x].v <= V)
            c[x].beg = L + 1, c[x].end = L;
        else
        {
            c[x].beg = c[x].d;
            double tmp = (V * V - c[x].v * c[x].v) * 0.5 / c[x].a;
            if (ceil(tmp) == tmp)
                c[x].end = c[x].d + min(L, ll(tmp - 1));
            else
                c[x].end = c[x].d + min(ll(floor(tmp)), L);
        }
    }
    for (int i = c[x].beg; i <= min(c[x].end, L); i++)
        vis[i].push_back(x);
    return;
}
int main()
{
    ios::sync_with_stdio(false);
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    cin >> T;
    while (T--)
    {
        ll ans = 0, cnt = 0;
        cin >> n >> m >> L >> V;
        for (ll i = 1; i <= n; i++)
        {
            cin >> c[i].d >> c[i].v >> c[i].a;
            calc(i);
        }
        // for (int i = 1; i <= n; i++)
        //     cerr << c[i].beg << " " << c[i].end << "\n";
        // for (int i = 1; i <= L; i++)
        // {
        //     if (!vis[i].empty())
        //     {
        //         cerr << i << ":";
        //         for (auto j : vis[i])
        //             cerr << j << " ";
        //         cerr << "\n";
        //     }
        // }
        for (int i = 1; i <= m; i++)
        {
            cin >> p[i];
            if (!vis[p[i]].empty())
            {
                bool flag = false;
                for (int j = 0; j < vis[p[i]].size(); j++)
                {
                    if (!cc[vis[p[i]][j]])
                    {
                        cc[vis[p[i]][j]] = true, flag = true, ans++;
                        // cerr << vis[p[i]][j] << " ";
                    }
                }
                if (!flag)
                    cnt++;
            }
            else
                cnt++;
        }
        // cerr << "\n";
        cout << ans << " " << cnt << "\n";
        for (ll i = 1; i <= n; i++)
            cc[i] = 0, c[i].a = 0, c[i].d = 0, c[i].v, c[i].beg = INF, c[i].end = INF - 1;
        for (ll i = 1; i <= L; i++)
            vis[i].clear();
    }
    return 0;
}